# 求矩阵主对角线元素之和
def main(matrix: list) -> int:
    sum = 0
    for i in range(len(matrix)):
        for j in range(len(matrix)):
            if i == j:
                sum += matrix[i][j]
    return sum


if __name__ == "__main__":
    matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
    print(main(matrix))
